<?php
session_start();
require './lib/ConnectDB.php';
$userid = $_SESSION['id_user'];
$description = $_POST['txtarea'];
 if ($_FILES['file']['tmp_name']) {
     
     if ($_FILES['file']['size'] > 2097152) {
                $_SESSION['erorr']="Снимката е твърде голяма!";
            }
             if ($_FILES['file']['type'] == 'image/jpeg' ||
                $_FILES['file']['type'] == 'image/gif'  ||
                $_FILES['file']['type'] == 'image/png'//todo
                    ) {
                                $img_name = time().'_'.$_FILES['file']['name'];
 $path = 'img'.DIRECTORY_SEPARATOR.$_SESSION['name'].DIRECTORY_SEPARATOR.$img_name;
 if(move_uploaded_file($_FILES['file']['tmp_name'], $path)){
     $insert_img = ConnectDB::getInstace();
     $insert_img->cDB()->query("INSERT INTO images(id_user,img_path,visible,description)
         values('$userid','$img_name','1','$description')");
     
 }
 
                    }else
                    {$_SESSION['erorr']="Моля изберете изображение което е във формат JPG,PNG или GIF";}
      
 }
 header("Location:dashboard.php");